package com.kehutong.admin.util;

import org.coraframework.cache.Cache;
import org.coraframework.cache.support.LRUCache;
import org.coraframework.inject.Singleton;

@Singleton
public class CacheUtil {

    private Cache<String, Object> map = new LRUCache<>("", 50*1024*1024, 20*60*1000);


    public void remove(String... keys) {
        for (String key : keys) {
            remove(key);
        }
    }

    public void remove(String key) {
        this.map.remove(key);
    }

    @SuppressWarnings("unchecked")
	public <T> T get(String key) {
        return (T)map.get(key);
    }

    public <T> boolean set(String key, T value) {
        map.put(key, value);
        return true;
    }

    public <T> boolean set(String key, T value, Long expireTime) {
    	 map.put(key, value);
        return true;
    }

    public void expire(String key, Long expireTime) {
        this.map.remove(key);
    }

}
